package com.lonwin.inspectionmanagement.mvp.presenter;

import android.app.Application;

import com.jess.arms.integration.AppManager;
import com.jess.arms.di.scope.ActivityScope;
import com.jess.arms.mvp.BasePresenter;
import com.jess.arms.http.imageloader.ImageLoader;

import me.jessyan.rxerrorhandler.core.RxErrorHandler;
import me.jessyan.rxerrorhandler.handler.ErrorHandleSubscriber;

import javax.inject.Inject;

import com.jess.arms.utils.DataHelper;
import com.lonwin.inspectionmanagement.app.AppConstants;
import com.lonwin.inspectionmanagement.app.utils.AppUtil;
import com.lonwin.inspectionmanagement.app.utils.DataUtil;
import com.lonwin.inspectionmanagement.app.utils.RxUtils;
import com.lonwin.inspectionmanagement.mvp.contract.UpcomingListContract;
import com.lonwin.inspectionmanagement.mvp.model.entity.bean.ConfigBean;
import com.lonwin.inspectionmanagement.mvp.model.entity.bean.UpcommingBean;

import java.util.HashMap;
import java.util.Map;


/**
 * ================================================
 * Description:
 * <p>
 * Created by MVPArmsTemplate on 12/25/2018 21:49
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms">Star me</a>
 * <a href="https://github.com/JessYanCoding/MVPArms/wiki">See me</a>
 * <a href="https://github.com/JessYanCoding/MVPArmsTemplate">模版请保持更新</a>
 * ================================================
 */
@ActivityScope
public class UpcomingListPresenter extends BasePresenter<UpcomingListContract.Model, UpcomingListContract.View> {
    @Inject
    RxErrorHandler mErrorHandler;
    @Inject
    Application mApplication;
    @Inject
    ImageLoader mImageLoader;
    @Inject
    AppManager mAppManager;
   ConfigBean configBean;
    @Inject
    public UpcomingListPresenter(UpcomingListContract.Model model, UpcomingListContract.View rootView) {
        super(model, rootView);
        configBean=DataHelper.getDeviceData(mRootView.getMyActivity(),AppConstants.EXTRA_CONFIG_DATA);

    }

    public ConfigBean getConfigBean() {
        return configBean;
    }


    /**
     * 获取待办记录列表
     */
    public void getBacklogXcjlb()
    {
        Map<String,Object> maps=new HashMap<>();
        String url=DataUtil.getJNUrl(configBean)+"/hzxh";
        if (configBean.getCurrentRole().getRoleCode().equals(AppConstants.ROLE_LLY)||configBean.getCurrentRole().getRoleCode().equals(AppConstants.ROLE_LDBM))
        {
            url+="/xcrecordController/getBacklogXcjlb";
            maps.put("groupids",AppUtil.getgroupids(configBean));
        }else {
            url+="/xcrecordController/getHzUnCheckXcjlb";
            maps.put("hzid",configBean.getGpsId());
        }
        mModel.getBacklogXcjlb(url,maps).compose(RxUtils.applySchedulers(mRootView))
                .subscribe(new ErrorHandleSubscriber<UpcommingBean>(mErrorHandler) {
                    @Override
                    public void onNext(UpcommingBean upcommingBean) {
                        mRootView.getBacklogXcjlbSuccess(upcommingBean.getData());
                    }
                });
    }

    @Override
    public void onDestroy() {
        super.onDestroy();
        this.mErrorHandler = null;
        this.mAppManager = null;
        this.mImageLoader = null;
        this.mApplication = null;
    }
}
